<?php
    /*
    * status legend
    * status = 0 =>  pocetno stanje
    * status = 1 =>  validan - placanje uspesno 
    * status = 2 =>  otkazan
    * status = 3 =>  validan - rezervacija sa sistema
    * status = 4 =>  ceka proces placanja  
    */
    require_once($application_folder."/controllers/navigator.php");
    class home extends Navigator { 

        function home () {
            parent::Navigator(); 
            $this->data['p'] = 'home';

            /*HELPERS*/
            $this->load->helper('date');
            $this->load->helper('timemaker');

            /*MODELS*/
            $this->load->model('status_m','statusm');
            $this->load->model('users_m','usersm'); 

            /*ASSETS*/
            $this->carabiner->js('jquery-ui-1.8.5.custom.min.js');   
            $this->carabiner->js('jquery.simplemodal.js');   
            $this->carabiner->css('jquery-ui.css');    
            
            $this->data['language'] = $this->lang_ses->getLang();
            
            /*Class*/
            $this->load->library('translate');
                
            //set local language
            $this->translate->setLang($this->lang_ses->getLang());

        }

        function index() {              

            /*LOGIN*/
            $this->usersm->check_log(1);

            $this->title("SOHO - Booking View");
            $this->carabiner->js('tablesorter/jquery.tablesorter.js');
            $this->carabiner->js('tablesorter/pager/jquery.tablesorter.pager.js');
            $this->carabiner->js('home.js');  
            $this->carabiner->css('tablesorter/style.css');          

            $this->data['status0']=array();

            $this->navigate('/home/content/table_0_v');

            $this->trace('Site Page',$this->data['p']);
        }  

        /*
        *uzima niz datuma iz excusrionbooking
        */
        function exc_dates()
        {
            $this->statusm->getBookingDates();   
        }      

        /*
        *filtrira podatke za prikaz u tablesorter-u
        */
        function exc_filter()
        {
            //videti za $type
            $datum ="all days";
            if(!isset($_POST['excdate']) )
            {
                $this->data['status0'] = $this->statusm->readStatus0();
                //echo json_encode(array('success'=>'nema time stamp'));   
            }
            else
            {
                //$excdate = $_POST['excdate'];
                //echo json_encode(array('success'=>'ima time stamp ' . date("d.M.Y", 1286748000)));    
                $this->data['status0'] = $this->statusm->filterStatus0();   
            }    


            echo json_encode($this->load->view('home/content/status_exc_table_v',$this->data['status0'],TRUE));   
        }

        /*
        *otkazuje buking stattus na 0 za taj booking
        */
        function excstatus()
        {
            $this->statusm->update_status_exc();
        }

        /*
        *uzima niz datuma iz tourbooking
        */
        function tr_dates()
        {
            $this->statusm->getTrBookingDates();   
        }
        
        
        /*
        *filtrira podatke za prikaz u tablesorter-u
        */
        function tr_filter()
        {
            //videti za $type
            $datum ="all days";
            if(!isset($_POST['trdate']) )
            {
                $this->data['status1'] = $this->statusm->readStatus1();
                //echo json_encode(array('success'=>'nema time stamp'));   
            }
            else
            {
                //$excdate = $_POST['excdate'];
                //echo json_encode(array('success'=>'ima time stamp ' . date("d.M.Y", 1286748000)));    
                $this->data['status1'] = $this->statusm->filterStatus1();   
            }    


            echo json_encode($this->load->view('home/content/status_tr_table_v',$this->data['status1'],TRUE));   
        }
        
        /*
        *otkazuje buking stattus na 0 za taj booking
        */
        function trstatus()
        {
            $this->statusm->update_status_tr();
        }
        
        
        
        
        function test_returnOK_results_excursion(){
            $booking_id = 58;
            $url = 'http://www.informacionisistem.com/excursionstours/returnOk/test_returnOK_results';

            //SET SESSION DATA TO UPDATE BOOKING STATUS IF PAYMENT IS SUCESSFULL
            $this->session->userdata('payment_type');
            $this->session->set_userdata('payment_type', 'excursion');
            $this->session->set_userdata('ec_id', $booking_id);

            redirect($url); // redirect to secure server!
        }

        function test_returnOK_results_tour(){
            $booking_id = 2;
            $url = 'http://www.informacionisistem.com/excursionstours/returnOk/test_returnOK_results';

            //SET SESSION DATA TO UPDATE BOOKING STATUS IF PAYMENT IS SUCESSFULL
            $this->session->userdata('payment_type');
            $this->session->set_userdata('payment_type', 'tour');
            $this->session->set_userdata('t_id', $booking_id);

            redirect($url); // redirect to secure server!
        }

        function test_returnOK_results_rentacar(){
            $booking_id = 366;
            $url = 'http://www.informacionisistem.com/excursionstours/returnOk/test_returnOK_results';

            //SET SESSION DATA TO UPDATE BOOKING STATUS IF PAYMENT IS SUCESSFULL
            $this->session->userdata('payment_type');
            $this->session->set_userdata('payment_type', 'rentacar');
            $this->session->set_userdata('cb_id', $booking_id);

            redirect($url); // redirect to secure server!
        }

    }
?>